package LeetCode.month03.day69;

import java.util.Arrays;

/**
 * @author 16778
 * @date 2025/10/8 8:04
 * @description
 */
public class No2300 {
    public int[] successfulPairs(int[] spells, int[] potions, long success) {
        int n = spells.length;
        int m = potions.length;
        Arrays.sort(potions);
        int[] res = new int[n];
        double[] arr = Arrays.stream(potions)
                .asDoubleStream()
                .toArray();

        for (int i = 0; i < n; i++) {
            double num = (double)success/spells[i];
            int index = binarySearch(arr,num);
            res[i] = m-index;
        }
        return res;
    }

    public int binarySearch(double[] arr,double target){
        int left = 0,right = arr.length-1;
        while(left<=right){
            int mid = left + (right-left)/2;
            if(arr[mid]>=target) right = mid-1;
            else left = mid+1;
        }
        return left;
    }
}
